<template>
  <div>
    <span class="title"><a @click.prevent="goBack" class="back-class" href="#">返回</a></span>
    <el-card>
      <ul class="model-ul">
        <li  v-for="item in sourceData" :key="item.Id">
          <a href="#" @click.prevent="gotoMode('V', item)">
            <div class="addItem">
              <span>{{item.Title.slice(0, 4) || '名称'}}</span>
            </div>
          </a>
        </li>
        <li>
          <a href="#" @click.prevent="gotoMode">
            <div class="addItem">
              <i class="iconfont el-icon-circle-plus-outline" style="font-size: 60px; color: #EEEEEE"></i>
            </div>
          </a>
        </li>
      </ul>
      <model-dialog :formData="formData" :visible.sync="modelVisible"></model-dialog>
    </el-card>
  </div>
</template>

<script>
import projectDocApi from '@/api/projectDocApi'
import ModelDialog from "./modelDialog";

export default {
  name: "modelMain",
  components: {
    ModelDialog
  },
  data () {
    return {
      modelVisible: false,
      projectId: this.$route.params.id,
      sourceData: [],
      formData: {}
    }
  },
  mounted() {
    this.getInitData()
  },
  methods: {
    goBack () {
      this.$router.push(`/view/project/needlist/${this.projectId}`)
    },
    gotoMode (type, item) {
      console.log(type, item)
      if (type === 'V') {
        this.$router.push(`/view/project/modelingIndex/${item.Id}`)
      } else {
        this.formData = {
          Projectid: this.projectId
        }
        this.modelVisible = true
      }
    },
    getInitData () {
      projectDocApi.getPage({id: this.projectId}).then(res => {
        if (res.Doc) {
          this.sourceData = res.Doc
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
.model-ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  li {
    margin-right: 20px;
    margin-bottom: 10px;
  }
}
.addItem {
  width: 100px;
  height: 100px;
  margin: auto;
  border: 3px dotted #EEEEEE;
  display: flex;
  align-items: center;
  justify-content: center
}
</style>